﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Uzi.Packaging
{
    /// <summary>
    /// Parts folder container
    /// </summary>
    public class PartsFolder : ICorePart, INotifyPropertyChanged
    {
        #region constructor
        public PartsFolder(ICorePart parent, string name, IEnumerable<ICorePart> parts, Type partType)
        {
            _Parent = parent;
            _Name = name;
            _Parts = parts;
            _PartType = partType;
        }

        public PartsFolder(ICorePart parent, string name, Type partType, params ICorePart[] parts)
            : this(parent, name, parts, partType)
        {
        }
        #endregion

        #region private data
        private ICorePart _Parent;
        private string _Name;
        private IEnumerable<ICorePart> _Parts;
        private Type _PartType;
        #endregion

        public ICorePart Parent { get { return _Parent; } }
        public string Name { get { return _Name; } }
        public IEnumerable<ICorePart> Relationships
        {
            get
            {
                foreach (var _rel in _Parts)
                    yield return _rel;
                yield break;
            }
        }

        public Type PartType { get { return _PartType; } }
        public string TypeName { get { return this.GetType().FullName; } }

        /// <summary>Call to inform listeners that the relationships may have changed</summary>
        public void ContentsChanged()
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(@"Relationships"));
        }

        [field: NonSerialized]
        public event PropertyChangedEventHandler PropertyChanged;
    }
}
